package com.zjxny.model;

import java.util.Date;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import lombok.Getter;
import lombok.Setter;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.Drill;
import xyz.erupt.annotation.sub_erupt.Link;
import xyz.erupt.annotation.sub_erupt.LinkTree;
import xyz.erupt.annotation.sub_erupt.Power;
import xyz.erupt.annotation.sub_erupt.RowOperation;
import xyz.erupt.annotation.sub_erupt.Tpl;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.ChoiceType;
import xyz.erupt.annotation.sub_field.sub_edit.DateType;
import xyz.erupt.annotation.sub_field.sub_edit.ReferenceTableType;
import xyz.erupt.annotation.sub_field.sub_edit.ReferenceTreeType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;
import xyz.erupt.upms.handler.DictCodeChoiceFetchHandler;
import xyz.erupt.upms.model.base.HyperModel;

@Setter
@Getter
@Entity
@Table(name = "traffic_info")
@Erupt(
		name = "违章信息", 
		linkTree = @LinkTree(field = "accountInfo"), 
		power = @Power(add = false, delete = false, edit = false, query = true, importable = false, export = true),
		drills = {
                @Drill(code = "drill", 
                       title = "违章明细",
                       //最终生成的表达式为：EruptTest.id = DrillErupt.eruptTestId
                       link = @Link(column = "hphm",                // 当前表关联列
                                    linkErupt = TrafficDetail.class, // 目标关联表
                                    joinColumn = "hphm"))  // 目标表关联列
       }
	   ,rowOperation= {
				@RowOperation(
						title="照片",
						icon ="fa fa-photo",
						ifExpr="item.photos.length>0",
						type = RowOperation.Type.TPL,
		                tpl = @Tpl(
		                        path = "/tpl/freemarker/carphoto.ftl",     //模板文件路径
		                        tplHandler=TrafficInfo.class,
		                        engine = Tpl.Engine.FreeMarker
		                )
				)
		}
)
public class TrafficInfo extends HyperModel implements Tpl.TplHandler{

	private static final long serialVersionUID = -880084060382830670L;
	
	@EruptField(
	        views =  @View(title = "所属公司", column = "simpleTitle"),
    		edit = @Edit(
    		            title = "所属公司"
    		            ,type = EditType.REFERENCE_TREE
    		            ,referenceTreeType = @ReferenceTreeType(pid = "parent.id",label = "simpleTitle")
    		)
	    )
	@ManyToOne
	AccountInfo accountInfo;
	
	@EruptField(
			views = {
			        @View(title = "号牌号码", column = "hphm")
			    },
    		edit = @Edit(
    		            title = "车辆信息"
	            		,type = EditType.REFERENCE_TABLE,
	                	referenceTableType = @ReferenceTableType(id = "id", label = "号牌号码")
    		            ,search = @Search(vague = true)
    		)
	    )
	@ManyToOne
	CarInfo CarInfo;
	
	@EruptField(views = @View(title = "未处理数"), edit = @Edit(show = false, title = "未处理数"))
	String num;// null
	
	@EruptField(views = @View(title = "号牌号码"), edit = @Edit(show = false, title = "号牌号码", search=@Search(vague = true)))
	String hphm;// "粤BDJ1450",

	@EruptField(views = @View(title = "违法时间"), edit = @Edit(show = false, title = "违法时间",search=@Search(vague=true),type = EditType.DATE, dateType = @DateType(type = DateType.Type.DATE)))
	@Column(name = "wfsj", columnDefinition="date")
	Date wfsj;// "2023-08-02 08:53",

	@EruptField(views = @View(title = "违法描述", show = false), edit = @Edit(show = false, title = "违法描述"))
	String wfms;// "驾驶机动车违反道路交通信号灯通行的",

	@EruptField(views = @View(title = "罚款金额"), edit = @Edit(show = false, title = "罚款金额"))
	String fkje;// "200",

	@EruptField(views = @View(title = "记分值"), edit = @Edit(show = false, title = "记分值"))
	String wfjfs;// null,

	@EruptField(views = @View(title = "wfzt", show = false), edit = @Edit(show = false, title = "wfzt"))
	String wfzt;// null,

	@EruptField(views = @View(title = "xh", show = false), edit = @Edit(show = false, title = "xh"))
	@Column(name = "xh", columnDefinition="char(16)")
	String xh;// "4413227901922704",

	@EruptField(views = @View(title = "号牌种类", show = false), edit = @Edit(show = false, title = "号牌种类"))
	String hpzl;// "52",

	@EruptField(views = @View(title = "违法地址", show = false), edit = @Edit(show = false, title = "违法地址"))
	String wfdz;// "博罗县217县道看守所路口",

	@EruptField(views = @View(title = "违法编码", show = false), edit = @Edit(show = false, title = "违法编码",search = @Search(vague = true)))
	String wfxw;// "1625",

	@EruptField(views = @View(title = "处理标记", show = false), edit = @Edit(show = false, title = "处理标记",search=@Search
			,type = EditType.CHOICE
			,choiceType=@ChoiceType(fetchHandler = DictCodeChoiceFetchHandler.class,fetchHandlerParams = {"traffic_clbj"} )))
	String clbj;// "1",
	
	@Column(name = "clbj_str", columnDefinition="varchar(40)")
	@EruptField(views = @View(title = "处理标记",show = false), edit = @Edit(show = false, title = "处理标记"))
	String clbjStr;// null,

	@EruptField(views = @View(title = "交款标记", show = false), edit = @Edit(show = false, title = "交款标记",search=@Search
			,type = EditType.CHOICE
			,choiceType=@ChoiceType(fetchHandler = DictCodeChoiceFetchHandler.class,fetchHandlerParams = {"traffic_jkbj"} )))
	String jkbj;// "1",

	@EruptField(views = @View(title = "违法处理时间"), edit = @Edit(show = false, title = "违法处理时间",search=@Search(vague=true),type = EditType.DATE, dateType = @DateType(type = DateType.Type.DATE)))
	@Column(name = "clsj", columnDefinition="date")
	Date clsj;// "2023-10-13 15:05",

	@Column(name = "jkbj_str", columnDefinition="varchar(40)")
	@EruptField(views = @View(title = "jkbjStr",show=false), edit = @Edit(show = false, title = "jkbjStr"))
	String jkbjStr;// null,

	@EruptField(views = @View(title = "采集单位"), edit = @Edit(show = false, title = "采集单位"))
	String cjjgmc;// null,

	@EruptField(views = @View(title = "cjjg", show = false), edit = @Edit(show = false, title = "cjjg"))
	String cjjg;// null,

	@EruptField(views = @View(title = "gxsj", show = false), edit = @Edit(show = false, title = "gxsj"))
	String gxsj;// null,

	@EruptField(views = @View(title = "scz", show = false), edit = @Edit(show = false, title = "scz"))
	String scz;// null,

	@EruptField(views = @View(title = "bzz", show = false), edit = @Edit(show = false, title = "bzz"))
	String bzz;// null,

	@EruptField(views = @View(title = "wfxwmc", show = false), edit = @Edit(show = false, title = "wfxwmc"))
	String wfxwmc;// null,

	@EruptField(views = @View(title = "hpzlmc", show = false), edit = @Edit(show = false, title = "hpzlmc"))
	String hpzlmc;// null,

	@EruptField(views = @View(title = "swjgbj", show = false), edit = @Edit(show = false, title = "swjgbj"))
	String swjgbj;// "0",

	@EruptField(views = @View(title = "jdsbh", show = false), edit = @Edit(show = false, title = "jdsbh"))
	String jdsbh;// null,

	@EruptField(views = @View(title = "glbm", show = false), edit = @Edit(show = false, title = "glbm"))
	String glbm;// null
	
	@EruptField(views = @View(title = "photos"), edit = @Edit(show = false, title = "photos"))
	@Column(name = "photos", columnDefinition="text")
	private String photos;

	@Override
	public void bindTplData(Map<String, Object> binding, String[] params) {
		binding.put("title", "违章照片");
	}
}